home *** CD-ROM | disk | FTP | other *** search
- // %filename% -- data access methods
- // Created %date% %time% by AppMaker
-
- // This module contains data structures to access the data in your
- // document's file(s). The intent is to isolate the details of the
- // data representation into this module and to provide accessor
- // functions for reading/writing logical pieces of the data.
- // For your application, you will probably rewrite most of this.
- // This module will not be regenerated by AppMaker unless you delete it.
-
- #include <CDocument.h>
- #include "%appname%Data.h"
-
- extern OSType gSignature; /* The application's signature */
-
- /*----------*/
- void C%appname%Data::I%appname%Data (CDocument *theDocument)
- {
- inherited::IDataFile ();
- hasFile = FALSE;
- itsDocument = theDocument;
-
- // your application-specific initialization
- itsData = NULL;
-
- } /* I%appname%Data */
-
- /*----------*/
- void C%appname%Data::Dispose (void)
- {
- DisposeData ();
- inherited::Dispose ();
- } /* Dispose */
-
- /*----------*/
- void C%appname%Data::OpenData (SignedByte permission)
- {
- Open (permission);
- hasFile = TRUE;
-
- ReadData ();
-
- } /* OpenData */
-
- /*----------*/
- void C%appname%Data::Close (void)
- {
- inherited::Close ();
- hasFile = FALSE;
- // don't DisposeData because data may be needed by SaveAs
- } /* Close */
-
- /*----------*/
- Boolean C%appname%Data::Save (void)
- {
- if (hasFile) {
- return (WriteData ());
- } else {
- // shouldn't be called in this case
- return (FALSE);
- }
- } /* Save */
-
- /*----------*/
- Boolean C%appname%Data::SaveAs (SFReply *macSFReply)
- {
- // If all of your data is in memory, then just close the current file
- // create and open a file, then save your data into the new file
- //
- // If some of your data is in the current file and not in memory,
- // you may have to create and open the new file,
- // copy data from the current file to the new file,
- // close the current file,
- // then save your data into the new file
-
- OSErr ignoreErr;
-
- if (hasFile) {
- Close ();
- }
- SFSpecify (macSFReply);
- ignoreErr = HDelete (volNum, dirID, name); // in case already exists
- CreateNew (gSignature, kFileType);
- Open (fsRdWrPerm);
- hasFile = TRUE;
-
- return (Save ());
- } /* SaveAs */
-
- /*----------*/
- void C%appname%Data::Revert (void)
- {
- DisposeData ();
- if (hasFile) {
- ReadData ();
- }
- } /* Revert */
-
-
- // The next few methods are for transferring data between the
- // data file and your internal data structures, and for disposing
- // your data structures. They are called by Open, Close, etc.
- // Replace their bodies with whatever is suitable for your application
-
- // define internal data structures to describe the file format:
- typedef struct {
- short stuff;
- } fileData;
-
- /*----------*/
- void C%appname%Data::ReadData (void)
- {
- itsData = ReadAll ();
- } /* ReadData */
-
- /*----------*/
- Boolean C%appname%Data::WriteData (void)
- {
- WriteAll (itsData);
- return (TRUE);
- } /* WriteData */
-
- /*----------*/
- void C%appname%Data::DisposeData (void)
- {
- if (itsData != NULL) {
- DisposHandle (itsData);
- itsData = NULL;
- }
- } /* DisposeData */
-
-
- // The remaining methods are for accessing your data as logical chunks.
- // These are just models for your own accessor functions;
- // they aren't called by any AppMaker-generated code.
- // Replace them with whatever is suitable for your application.
-
- /*----------*/
- void C%appname%Data::Get%appname% (void)
- {
- } /* Get%appname% */
-
- /*----------*/
- void C%appname%Data::Put%appname% (void)
- {
- } /* Put%appname% */
-
- /*----------*/
- void C%appname%Data::Add%appname% (void)
- {
- } /* Add%appname% */
-
- /*----------*/
- void C%appname%Data::Delete%appname% (void)
- {
- } /* Delete%appname% */
-
- /* %filename% */
-